package top.lyjwn.ajui.network;

import android.util.Log;

import com.alibaba.fastjson.JSONObject;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.handshake.ServerHandshake;

import java.net.URI;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * WebSocket客户端
 */
public class IWebSocketClient extends WebSocketClient {
    public IWebSocketClient(URI serverUri, Map<String, String> httpHeaders) {
        this(serverUri, httpHeaders, 60 * 1000);
    }


    public IWebSocketClient(URI serverUri, Map<String, String> httpHeaders, int connectTimeout) {
        super(serverUri, new Draft_6455(), httpHeaders, connectTimeout);
    }

    @Override
    public void onOpen(ServerHandshake handshakedata) {
        Log.d("webSocket open", JSONObject.toJSONString(handshakedata));
    }

    @Override
    public void onMessage(String message) {
        Log.d("webSocket onMessage", message);
    }

    @Override
    public void onClose(int code, String reason, boolean remote) {
        Log.d("webSocket close", reason);
    }

    @Override
    public void onError(Exception ex) {
        Log.d("webSocket error", ex.getMessage());
    }
}
